#ifndef KEY_H_
#define KEY_H_

#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_rcc.h"
#include "main.h"
#include "stdint.h"
#include "FreeRTOS.h"
#include "task.h"
#include "stdint.h"

#define LED_RED_PORT		GPIOC
#define LED_RED_PIN			GPIO_PIN_13
#define LED_RED_0			LED_RED_PORT->ODR &=~ LED_RED_PIN
#define LED_RED_1			LED_RED_PORT->ODR |=  LED_RED_PIN

#define LED_GREEN_PORT		GPIOE
#define LED_GREEN_PIN		GPIO_PIN_6
#define LED_GREEN_0			LED_GREEN_PORT->ODR &=~ LED_GREEN_PIN
#define LED_GREEN_1			LED_GREEN_PORT->ODR |=  LED_GREEN_PIN

#define LED_RCC_AHB1_EN		__HAL_RCC_GPIOC_CLK_ENABLE()

#define KEY_USE_MATRIX

#define KEY_RCC_APB			AHB1ENR
#define KEY_RCC_AHB1_EN		( RCC_AHB1ENR_GPIOEEN | RCC_AHB1ENR_GPIOBEN )
#define KEY_UP	0x01
#define KEY_DW	0x02
#define KEY_LF	0x04
#define KEY_RG	0x08
#define KEY_EN	0x10
#define KEY_ES	0x20

#ifdef KEY_USE_MATRIX
	#define KEY_LINE0_PORT		GPIOE
	#define KEY_LINE0_PIN		GPIO_PIN_4
	//
	#define KEY_LINE1_PORT		GPIOE
	#define KEY_LINE1_PIN		GPIO_PIN_5
	//
	#define KEY_UP_DW_PORT		GPIOE
	#define KEY_UP_DW_PIN		GPIO_PIN_2
	//
	#define KEY_LF_R_PORT		GPIOB
	#define KEY_LF_R_PIN		GPIO_PIN_9
	//
	#define KEY_EN_ESC_PORT		GPIOE
	#define KEY_EN_ESC_PIN		GPIO_PIN_3
#else
	#define KEY_UP_PORT			GPIOD
	#define KEY_UP_PIN			GPIO_Pin_8
	//
	#define KEY_DW_PORT			GPIOD
	#define KEY_DW_PIN			GPIO_Pin_14
	//
	#define KEY_LF_PORT			GPIOE
	#define KEY_LF_PIN			GPIO_Pin_1
	//
	#define KEY_RG_PORT			GPIOE
	#define KEY_RG_PIN			GPIO_Pin_0
	//
	#define KEY_ENTER_PORT		GPIOD
	#define KEY_ENTER_PIN		GPIO_Pin_12
	//
	#define KEY_ESC_PORT		GPIOC
	#define KEY_ESC_PIN			GPIO_Pin_13
#endif

void KeyGPIO_Init(void);
void KeyGet(uint8_t * key);

#endif
